package com.google.googlemarket.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.google.googlemarket.MyApp;
import com.google.googlemarket.http.BitmapHelp;
import com.google.googlemarket.http.Urls;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/9/20.
 */
public class BannerAdapter extends PagerAdapter {
    private final ArrayList<String> urls;
private final ArrayList<ImageView> imageViews = new ArrayList<>();
    public BannerAdapter(ArrayList<String> picture) {
        super();
        this.urls=picture;
        for (String url: urls) {
            ImageView imageView = new ImageView(MyApp.getmContext());
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            imageViews.add(imageView);
        }
    }

    @Override
    public int getCount() {
        return imageViews.size()*1000*500;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        position = position % imageViews.size();
        ImageView iv = imageViews.get(position);
        String Url = Urls.IMAGE+"?name="+urls.get(position);
        BitmapHelp.getBitmapUtils(iv.getContext()).display(iv,Url) ;
        container.addView(iv);
        return iv;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
